<template>
    <div>
        <iview-table
                ref="table"
                :baseURL="queryModel.baseURL"
                :menuId="dataModel.menuId"
                :columns="dataModel.columns"
                :order="dataModel.order"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :defaultFilters="queryModel.defaultFilters"
                v-on="{changeTotalSize:changeTotalSize,events:events,changeSelect:changeSelect}">
        </iview-table>
        <br>
        <iview-page
                :totalSize="pageModel.totalSize"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :pageSizeOpts="pageModel.pageSizeOpts"
                v-on="{changePageNumber:changePageNumber,changePageSize:changePageSize}">
        </iview-page>
        <Modal v-model="showModal" :closable='false' :mask-closable=true :width="500">
            <h3 slot="header" style="color:#2D8CF0">受理确认</h3>
            <Form :model="attendanceRecord" :label-width="100" label-position="right">
                <FormItem label="预计完成时间：" prop="requireCompleteDate" :error="oldPassError">
                    <Row>
                        <Col span="11">
                            <DatePicker format="yyyy-MM-dd" @on-change="changeDate" transfer="true" type="date" placeholder="请选择日期" style="width: 100%"></DatePicker>
                        </Col>
                        <Col span="2" align="center">-</Col>
                        <Col span="11">
                            <TimePicker format="HH:mm" @on-change="changeTime" transfer="true" type="time" placeholder="请选择时间" style="width: 100%"></TimePicker>
                        </Col>
                    </Row>
                </FormItem>
                <FormItem label="回复内容：">
                    <Input v-model="selectRow.replyContent" type="textarea" :autosize="{minRows: 4,maxRows: 5}" placeholder="请输入内容..."></Input>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button type="info" size="large" @click="doAccept">确认受理</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import iviewTable from '@/view/common/table/Table.vue';
    import iviewPage from '@/view/common/page/Page.vue';
    export default {
        components: {
            iviewTable,
            iviewPage
        },
        data () {
            return {
                baseURL: '/user/work',
                selectRows: [],
                selectRow: {},
                showModal: false,
                expectCompleteDate: '',
                expectCompleteTime: '',
                queryModel: {
                    // 网关代理路径(必须)+资源路径(可选)
                    baseURL: '/user/work',
                    defaultFilters: [
                        {'field': 'process_user_id', 'value1': this.$store.state.app.loginUser.id, 'operate': '=='},
                        {'field': 'status', 'value1': 3, 'operate': '!='}
                    ]
                },
                dataModel: {
                    menuId: -1,
                    columns: [
                        {
                            type: 'expand',
                            width: 50,
                            render: (h, params) => {
                                return h('div', {
                                    props: {
                                        row: params.row
                                    },
                                    style: {
                                    }
                                }, params.row.workContent)
                            }
                        },
                        {
                            title: '提交人',
                            key: 'submitUserName'
                        },{
                            title: '要求完成时间',
                            key: 'requireCompleteTime',
                            render: (h, params) => {
                                if (params.row.requireCompleteTime) {
                                    return h('span', this.$moment(params.row.requireCompleteTime).format('YYYY-MM-DD HH:mm'))
                                }
                            }
                        },{
                            title: '处理人',
                            key: 'processUserName'
                        },{
                            title: '受理时间',
                            key: 'acceptTime',
                            render: (h, params) => {
                                if (params.row.acceptTime) {
                                    return h('span', this.$moment(params.row.acceptTime).format('YYYY-MM-DD HH:mm'))
                                }
                            }
                        },{
                            title: '答复完成时间',
                            key: 'expectCompleteTime',
                            render: (h, params) => {
                                if (params.row.expectCompleteTime) {
                                    return h('span', this.$moment(params.row.expectCompleteTime).format('YYYY-MM-DD HH:mm'))
                                }
                            }
                        },{
                            title: '答复备注',
                            key: 'replyContent'
                        },{
                            title: '实际完成时间',
                            key: 'actualCompleteTime',
                            render: (h, params) => {
                                if (params.row.actualCompleteTime) {
                                    return h('span', this.$moment(params.row.actualCompleteTime).format('YYYY-MM-DD HH:mm'))
                                }
                            }
                        },{
                            title: '审核完成时间',
                            key: 'auditCompleteTime',
                            render: (h, params) => {
                                if (params.row.auditCompleteTime) {
                                    return h('span', this.$moment(params.row.auditCompleteTime).format('YYYY-MM-DD HH:mm'))
                                }
                            }
                        },{
                            title: '状态',
                            key: 'status',
                            render: (h, params) => {
                                let temp = params.row.status
                                if (temp === 0) {
                                    temp = '待受理'
                                } else if (temp === 1) {
                                    temp = '处理中'
                                } else if (temp === 2) {
                                    temp = '已解决'
                                } else if (temp === 3) {
                                    temp = '已完成'
                                }
                                return h('span', temp)
                            }
                        },{
                            title: '完成情况',
                            key: 'timeComplete',
                            width: 150,
                            render: (h, params) => {
                                let color = ''
                                let temp = params.row.timeComplete
                                if (temp === 0) {
                                    temp = '未完成'
                                } else if (temp === 1) {
                                    temp = '按时完成'
                                    color = 'green'
                                } else if (temp === 2) {
                                    temp = '超时完成'
                                    color = 'red'
                                }
                                return h('Tag',{
                                    props: {
                                        type: 'dot',
                                        color: color
                                    }
                                }, temp)
                            }
                        },
                        {
                            title: '操作',
                            width: 200,
                            align: 'center',
                            render: (h, params) => {
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'info',
                                            size: 'default'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            click: () => {
                                                this.accept(params.index, params.row)
                                            }
                                        }
                                    }, '受理'),
                                    h('Button', {
                                        props: {
                                            type: 'info',
                                            size: 'default'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            click: () => {
                                                this.resolve(params.index, params.row)
                                            }
                                        }
                                    }, '解决')
                                ]);
                            }
                        }
                    ],
                    order: 'id desc'
                },
                pageModel: {
                    totalSize: 0,
                    pageNumber: 1,
                    pageSize: 100,
                    pageSizeOpts: [10, 50, 100, 500]
                }
            };
        },
        methods: {
            events (item) {
            },
            accept (index, row) {
                if (row.status === 0) {
                    this.selectRow = row
                    this.showModal = true
                } else {
                    this.$bus.alert('warning', '该记录不符合条件')
                }
            },
            doAccept () {
                if (this.expectCompleteDate !== '') {
                    this.selectRow.expectCompleteTimeStr = this.expectCompleteDate
                }
                if (this.expectCompleteTime !== '') {
                    this.selectRow.expectCompleteTimeStr += ' ' + this.expectCompleteTime
                }
                let url = '/user/work/accept'
                this.$ajax.post(url, this.selectRow).then(response => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        this.$bus.alert('success', '受理成功')
                        this.expectCompleteDate = ''
                        this.expectCompleteTime = ''
                        this.showModal = false
                        this.refresh()
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            resolve (index, row) {
                if (row.status === 1) {
                    let url = '/user/work/resolve/' + row.id
                    this.$ajax.post(url).then(response => {
                        let {code, msg} = response.data
                        if (code === 0) {
                            this.$bus.alert('success', '操作成功')
                            this.refresh()
                        } else {
                            this.$bus.alert('error', msg)
                        }
                    })
                } else {
                    this.$bus.alert('warning', '该记录不符合条件')
                }
            },
            refresh () {
                this.$refs.table.refresh()
            },
            changeDate (val) {
                this.expectCompleteDate = val
            },
            changeTime (val) {
                this.expectCompleteTime = val
            },
            changeSelect (rows) {
                this.selectRows = rows
            },
            changeTotalSize (totalSize) {
                this.pageModel.totalSize = totalSize
            },
            changePageNumber (pageNumber) {
                this.pageModel.pageNumber = pageNumber
            },
            changePageSize (pageSize) {
                this.pageModel.pageSize = pageSize
            },
            init () {
                this.refresh()
            }
        },
        mounted () {
            this.init()
        }
    }
</script>

<style>

</style>
